package com.dream.model.app;

import java.io.Serializable;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Type;

import com.dream.model.base.AppUserModelBase;
import com.google.common.collect.Lists;

@Entity
@Table(name="t_app_group")
public class AppGroup extends AppUserModelBase implements Serializable {
	

	/**
	 * 
	 */
	private static final long serialVersionUID = 7285876103316520473L;

	@Id
	@GeneratedValue(generator = "mycode")
	@GenericGenerator(name = "mycode", strategy = "assigned")
	@Column(name = "id")
	private String id;
	
	@Column(name="name")
	private String name;
	
	@Column(name="deleted")
	@Type(type = "org.hibernate.type.NumericBooleanType")
	private boolean deleted;
	
	@OneToMany(fetch = FetchType.LAZY)
	@JoinColumn(name="group_id",updatable=false,insertable=false)
	private List<AppGroupResource> groupResources = Lists.newArrayList();
	
	@Transient
	private List<AppResource> myResources = Lists.newArrayList();
	
	public List<AppResource> getMyResources() {
		return myResources;
	}

	public void setMyResources(List<AppResource> myResources) {
		this.myResources = myResources;
	}

	public List<AppGroupResource> getGroupResources() {
		return groupResources;
	}

	public void setGroupResources(List<AppGroupResource> groupResources) {
		this.groupResources = groupResources;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public boolean isDeleted() {
		return deleted;
	}

	public void setDeleted(boolean deleted) {
		this.deleted = deleted;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		AppGroup other = (AppGroup) obj;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		return true;
	}
	
}
